﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Navigation;

namespace ChessOnline
{
    public interface INavigator
    {
        void Go(Page sender, string reciever);
    }
    
    public class Navigator : INavigator
    {
        private static Navigator instance = new Navigator();

        public static Navigator Instance
        {
            get { return Navigator.instance; }
        }

        private Dictionary<string, Uri> pages = new Dictionary<string, Uri>();

        public void Go(Page sender, string reciever)
        {
            if (pages.ContainsKey(reciever))
            {
                sender.NavigationService.Navigate(pages[reciever]);
            }
            else
            {
                string go_address = reciever;
                go_address = go_address.Substring(0, go_address.LastIndexOf('.'));
                go_address = go_address.Insert(0, "/");
                Uri uri = new Uri(go_address, UriKind.Relative);
                if (sender.NavigationService.Navigate(uri))
                {
                    pages.Add(reciever, uri);
                }
            }
        }
    }
}
